<template>
	<div>
		<el-row :gutter="10">
			<el-col :span="24">
				<el-card shadow="never" class="card">
					<div id="charts_one" style="width:100%;min-height:80vh">
            <Search size='small' :searchVisible="searchVisible" :searchData.sync="searchData"  :searchForm="searchForm" @refresh_list="index"></Search>
						<div class="btn-group" style="margin-bottom:11px;">
             <div>
                 <el-button type="info" :disabled="single" size="mini" icon="el-icon-view"  @click="binding(ids)"  >绑定生产订单</el-button>
             </div>
             <table-tool :searchVisible.sync="searchVisible"  :fieldList="fieldList" @refresh_list="index" :searchTool="true"></table-tool>
						</div>
					    <el-table :row-class-name="rowClass" @selection-change="selection"  @row-click="handleRowClick"  row-key="id"  :header-cell-style="{ background: '#eef1f6', color: '#606266' }" v-loading="loading"  ref="multipleTable" border class="eltable" :data="list"  style="width: 100%">		   
						    <el-table-column align="center" type="selection" width="42"></el-table-column>
<!--							<el-table-column align="center" type='' v-if="fieldList[0].checked" property="id" label="ID" show-overflow-tooltip width="70">-->
<!--							</el-table-column>-->
                <el-table-column align="center" type="index" label="No." width="50" >
                </el-table-column>
							<el-table-column align="center"  v-if="fieldList[1].checked" property="trayNum" :label="$t('field.Scan_trayNum')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[2].checked" property="userId" :label="$t('field.Scan_userId')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[3].checked" property="taskBillNo" :label="$t('field.Scan_taskBillNo')" show-overflow-tooltip width="" >
							</el-table-column>
                <el-table-column align="center"  v-if="fieldList[4].checked" property="inStockNo" :label="$t('field.Scan_inStockNo')" show-overflow-tooltip width="" >
                </el-table-column>
							<el-table-column align="center"  v-if="fieldList[5].checked" property="createTime" :label="$t('field.Scan_createTime')" show-overflow-tooltip width="" >
							</el-table-column>
						</el-table>
						<Page :total="page_data.total" :page.sync="page_data.page" :limit.sync="page_data.limit" @pagination="index" />
					</div>
				</el-card>
			</el-col>
		</el-row>

		<!--查看详情-->
		<Detail :info="detailInfo" :show.sync="dialog.detailDialogStatus" size="small" @refresh_list="index"></Detail>
	</div>
</template>
<script>
	import {
	    index, 
	    updateExt,
    binding,
	} from '@/api/app/scan'
	import Search from '@/components/common/Search.vue'
	import Page from '@/components/common/Page.vue'
	import TableTool from '@/components/common/TableTool.vue'
	import { confirm,param2Obj } from '@/utils/common'
	import Detail from '@/views/app/scan/detail.vue' 
	export default {
		name:'scan',
		components: {
			Search,
			Page,
			TableTool,
	        Detail,  
		},
		data(){
			return {
				dialog: {
	                    detailDialogStatus : false,           
				},
				fieldList:[
					{lable:'ID',checked:true},
				    {lable:this.$t('field.Scan_trayNum'),checked:true},
				    {lable:this.$t('field.Scan_userId'),checked:true},
				    {lable:this.$t('field.Scan_taskBillNo'),checked:true},
				    {lable:this.$t('field.Scan_inStockNo'),checked:true},
				    {lable:this.$t('field.Scan_createTime'),checked:true},
				],
				ids: [],
				selectRows:[],
				selectTotal:0,
				single:true,
				multiple:true,
				list: [],
				small_tables:{},
	            detailInfo:{},
				loading: false,
				page_data: {
					limit: 20,
					page: 1,
					total:20,
				},
				searchVisible:true,
				searchForm:[],
				searchData:{},
			}
		},
		methods: {
      binding(ids){
        this.$prompt('请输入生产订单号','提示',{
          confirmButtonText:'确定',
          cancelButtonText:'取消'
        }).then(({value})=> {
          binding({ids:this.ids,taskBillNo:value}).then(res =>{
            if (res.data === true){
              this.$message({
                type:'success',
                message:'绑定成功'
              })
              this.index()
            }
          })
        }).catch(() => {
          this.$message({
            type:'info',
            message:'取消输入'
          })
        })
      },
			index(){
				let param = {limit:this.page_data.limit,page:this.page_data.page}
				Object.assign(param, this.searchData,param2Obj(this.$route.fullPath))
				this.loading = true
				index(param).then(res => {
					this.list = res.data.data
					this.small_tables=res.sql_field_data
					this.page_data.total = res.data.total
					this.loading = false
					if(this.page_data.page == 1){
            this.searchForm = [
              {type:'Input',label:this.$t('field.Scan_trayNum'),prop:'trayNum',width:'150px'},
              {type:'Input',label:this.$t('field.Scan_taskBillNo'),prop:'taskBillNo',width:'150px'},
              {type:'datetime',label:this.$t('field.Scan_createTime'),prop:'createTime',width:'150px'},

            ]
					}
				})
			},
			updateExt(row,field){
				if(row.id){
					updateExt({id:row.id,[field]:row[field]}).then(res => {
						this.$message({message: this.$t('system.success'), type: 'success'})
					})
				}
			},
			detail(row){
				this.dialog.detailDialogStatus = true
				this.detailInfo = {id:row.id ? row.id : this.ids.join(',')}
			},
			selection(selection) {
			    this.selectRows=selection
			    this.selectTotal=selection.length
				this.ids = selection.map(item => item.id)
				this.single = selection.length === 0
				this.multiple = !selection.length
			},
			handleRowClick(row, rowIndex,event){
				if(event.target.className !== 'el-input__inner'){
					this.$refs.multipleTable.toggleRowSelection(row)
				}
			},
			rowClass ({ row, rowIndex }) {
				for(let i=0;i<this.ids.length;i++) {
					if (row.id === this.ids[i]) {
						return 'rowLight'
					}
				}
			},
		},	
		mounted(){
			this.index()
		}
	}
</script>
<style  lang="scss">
@import '@/assets/scss/common.scss';
</style>